import argparse
import asyncio

from data_dyne.lg_workflow_parallel import gen_survey
from data_dyne.log import logger


async def gen_test():
    topics = [
        "Graph Neural Networks",
        "Moe",
        "Retrieval-Augmented Generation",
    ]
    for i, topic in enumerate(topics[2:]):
        await gen_survey(topic, f"{i + 3}.md")


async def main():
    # 设置命令行参数解析
    parser = argparse.ArgumentParser(description="生成综述文章")
    parser.add_argument(
        "--topic",
        type=str,
        required=False,
        help="综述主题",
        default="Attention Mechanisms",
    )

    # 解析命令行参数
    args = parser.parse_args()

    # 设置输出文件路径
    output_file = "review.md"

    # 调用 gen_survey 生成综述
    try:
        await gen_survey(args.topic, output_file)
    except Exception as e:
        import traceback

        logger.error(f"生成综述时发生错误: {str(e)}")
        logger.error("详细堆栈信息:")
        logger.error(traceback.format_exc())


if __name__ == "__main__":
    asyncio.run(main())
    # asyncio.run(gen_test())
